package org.dailydev.mojo.birt;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Locale;

import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.site.renderer.SiteRenderer;

/**
 * Run JDepend and generate a site report.
 * 
 * @author roman.bosak@exist.com
 * @goal generate
 * @execute phase="compile"
 * @description Goal which generate the JDepend metrics.
 */
public class BirtReport extends AbstractMavenReport {

	/**
	 * @parameter expression="${project}"
	 * @readonly
	 */
	private MavenProject project;

	/**
	 * @parameter 
	 *            expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
	 * @readonly
	 */
	private SiteRenderer siteRenderer;

	/**
	 * Directory where the generated output site files will be located.
	 * 
	 * @parameter expression="${project.build.directory}/site"
	 * @required
	 */
	private String outputDirectory;

	protected void executeReport(Locale arg0) throws MavenReportException {
		try {
			BufferedReader reader = new BufferedReader(
					new FileReader(
							"c:/workbench/DailyDev/svn-mirrors/birt-maven-plugin/birt-maven-plugin/src/test/resources/target/reports/pmd.html"));

			String line = null;
			while ((line = reader.readLine()) != null) {
				getSink().rawText(line + "\n");
				line = reader.readLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/** {@inheritDoc} */
	public String getDescription(Locale arg0) {
		return "BIRT Report description";
	}

	/** {@inheritDoc} */
	public String getName(Locale arg0) {
		return "BIRT Report";
	}

	/** {@inheritDoc} */
	protected String getOutputDirectory() {
		return this.outputDirectory;
	}

	/** {@inheritDoc} */
	public String getOutputName() {
		return "birt-report";
	}

	/** {@inheritDoc} */
	protected MavenProject getProject() {
		return this.project;
	}

	/** {@inheritDoc} */
	protected SiteRenderer getSiteRenderer() {
		return this.siteRenderer;
	}

}
